<template>
  <div class="app-layout-sider">
    <el-container>
      <el-aside width="200px" class="layout-sider">
        <div class="logo">
          <img class="pic-logo" src="~@/assets/logo.svg" />
        </div>
        <el-menu class="menu-item" :default-active="current" @select="menuHandle">
          <template v-for="(menuInfo, index) in menu" :key="index">
            <el-menu-item :index="index">
              <el-icon><document /></el-icon>
              <template #title>{{ menuInfo.title }}</template>
            </el-menu-item>
          </template>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const current = ref('menu_1')
const menu = ref({
  menu_1: {
    icon: 'icon-fengche',
    title: '可视化',
    pageName: 'vizs',
    params: {},
  },
  menu_2: {
    icon: 'icon-niudan',
    title: '数据视图',
    pageName: 'views',
    params: {},
  },
  menu_3: {
    icon: 'icon-liuxing',
    title: '数据源',
    pageName: 'source',
    params: {},
  },
})
onMounted(() => {
  menuHandle()
})

function menuHandle(e) {
  console.log('sider menu e:', e)
  if (e) {
    current.value = e
  }
  console.log('sider menu current:', current.value)

  const linkInfo = menu.value[current.value]
  console.log('[home] load linkInfo:', linkInfo)
  router.push({ name: linkInfo.pageName, params: linkInfo.params })
}
</script>

<style lang="less" scoped>
.app-layout-sider,
.el-container {
  height: 100%;
}
.layout-sider {
  border-top: 1px solid #e8e8e8;
  border-right: 1px solid #e8e8e8;
  background-color: #fafafa;
  overflow: auto;
}
.logo {
  border-bottom: 1px solid #e8e8e8;
}
.pic-logo {
  height: 32px;
  margin: 10px;
}
.el-main{
  padding: 5px;
}
</style>
